#ifndef _SCHEDULER_H_
#define _SCHEDULER_H_

#include <pthread.h>
#include <ProcessComposition.h>
#include <string>
#include <vector>
#include <Queue.h>
#include <ReadyQ.h>

class Scheduler{
public:
	ProcessComposition* get(unsigned char slot, int spe_id);
	void put(ProcessComposition &p, int state);
	void Put(vector<ProcessComposition*> &procs);


	int LiveProcesses();
	void StopWhenEmpty(){stop_when_empty = 0;};
	int stop_when_empty;
	~Scheduler(){}
	static Scheduler* Instance();
protected:
	Scheduler();
	Scheduler(const Scheduler&);
	Scheduler & operator=(const Scheduler&);
private:
	static Scheduler *sinstance;
	Queue<ProcessComposition> init_q;
	//Queue<ProcessComposition> active_q[MAX_SPU_SLOTS];
	ReadyQ ready_q;
	int pid_counter;
	pthread_mutex_t sched_mutex;
	int live_processes;
	void PutProcess(ProcessComposition &p, int state);

	bool check[10000];

	ProcessComposition *lastRun[NUMTHREADS][MAX_SPU_SLOTS];
};

#endif
